package com.hmall.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.pojo.ItemDoc;
import com.hmall.pojo.RequestParams;
import com.hmall.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class searchController {

    @Autowired
    private SearchService searchService;

    /**
     * 自动补全
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return searchService.getSuggestions(prefix);
    }

    /**
     * 聚合
     * @param params
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    @PostMapping("list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params){
        return searchService.search(params);
    }
}
